<template>
	<view class="content">
		<!-- 渐变背景 -->
		<view class="gradient">
			
			<text id="top_text">-始于思绪，跃于指尖-</text>
			
			<view id="toSearch">
				<input type="text" placeholder="Search..." confirm-type="search">
				<image src="../../static/icon/search.png" id="search_img"></image>
			</view>
	         
<!--		<view id="time">
				<view id="t_date">
					<view>{{date_m}} / {{date_d}}</view>
					<view id="date_yy">{{date_y}}</view>
				</view>
				<view id="t_day"><span>{{date_day}}</span></view>
			</view>
			<text>[距您上次思考已经过去了{{pass}}天]</text>   -->
		</view>
		
		<!-- 音乐模块 -->

		<view class="bg_music" @tap="audioPlay">
			<image src="../../static/images/music_icon.png" class="musicImg" :class="isPlay?'music_icon':''" />
			<image src="../../static/images/music_play.png" class="music_play" :class="isPlay?'pauseImg':'playImg'" />
		</view>
		<audio id="myAudio" :src="audioUrl" autoplay loop></audio>	
			
		
		<!-- 导航 -->
	    <view class="nav" >
			<view class="nav_box idea" @tap="gotoNotes"> 
				<image src="../../static/icon/idea.png"></image>  
				<view>记录灵感 >> </view>
			</view>
			<view class="nav_box timeline" @tap="gotoTimeline"> 
				<image src="../../static/icon/timeline.png"></image>   
				<view>时间轴 >> </view>
			</view>
		</view>
		
		<view class="nav_2">
			<view id="weather"> 晴 25℃</view>
			<view id="sentence"> 宜：思考 记灵感</view>
			<view id="time">
				<view id="t_date">
					<view>{{date_m}} / {{date_d}}</view>
					<view id="date_yy">{{date_y}} {{date_day}}</view>
				</view>
			</view>

		</view>
		
		
	</view>
</template>


















<script>
	export default {

		data: function() {
			return {
				'pass': '7',
				'date_d': '00',
				'date_y': '2020',
				'date_m':'Aay',
				'date_day':'Monday',
				isPlay: true,
				audioCtx: ''
			}
		},
		onLoad: function() {
			this.getTime(this);
			const that = this
			that.audioCtx = uni.createAudioContext('myAudio')
			//that.getMusicUrl()
		},
		onShow: function() {
			const that = this
			that.isPlay = true
			//that.getMusicUrl()
		},

		methods: {
			// 导航跳转
			gotoNotes(){
				uni.navigateTo({
					url:'../notes/notes'
				})
			},
			gotoTimeline(){
				uni.navigateTo({
					url:'../timeline/timeline'
				})
			},
			//获取当前时间
			getTime(){
			     let date = new Date();
				 
			     var y = date.getFullYear();
				 
			     var m = date.getMonth();
				   m = m+1;
				 
			     let d = date.getDate();
			     d = d < 10 ? ('0' + d) : d;//天补0
				
				 let dd = date.getDay();
			     switch(dd){
					 case 0 : dd = 'Monday';break;
					 case 1 : dd = 'Tuesday';break;
					 case 2 : dd = 'Wednesday';break;
					 case 3 : dd = 'Thursday';break;
					 case 4 : dd = 'Friday';break;
					 case 5 : dd = 'Saturday';break;
					 case 6 : dd = 'Sunday';break;
				 }
				 this.date_d = d;
				 this.date_y = y;
				 this.date_m = m;
				 this.date_day = dd;
			},
			audioPlay: function() {
				const that = this
				if (that.isPlay) {
					that.audioCtx.pause()
					that.isPlay = !that.isPlay
					tools.showToast('您已暂停音乐播放~')
				} else {
					that.audioCtx.play()
					that.isPlay = !that.isPlay
					tools.showToast('背景音乐已开启~')
				}
			},
			// 从云数据库获取音乐
			/*getMusicUrl: function() {
				const that = this
				const db = uni.cloud.database()
				const music = db.collection('music')
				music.get().then(res => {
					that.audioUrl = res.data[0].musicUrl
					that.audioCtx.loop = true
					that.audioCtx.play()
				})
			},*/
		}
	}
</script>



<style>
	@import url("../../static/style/index.css");
</style>
